﻿using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using LibVLCSharp.Shared;

namespace ui.test.Views;

public partial class UserControl3 : UserControl
{
    private static LibVLC _libVlc;
    private static MediaPlayer _mediaPlayer;

    public UserControl3()
    {
        InitializeComponent();
        Core.Initialize();
        try
        {
            _libVlc = new(["--plugin-path=" + @"libvlc\win-x64\plugins"]);
            _mediaPlayer = new(_libVlc);
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
            throw;
        }
    }

    public override void EndInit()
    {
        base.EndInit();
    }

    protected override void OnGotFocus(GotFocusEventArgs e)
    {
        base.OnGotFocus(e);
    }

    protected override void OnLoaded(RoutedEventArgs e)
    {
        base.OnLoaded(e);
    }

    protected override void OnUnloaded(RoutedEventArgs e)
    {
        base.OnUnloaded(e);

        _mediaPlayer.Dispose();
        _libVlc.Dispose();
    }

    // private void Button_OnClick(object? sender, RoutedEventArgs e)
    // {
    //     OverlayLayer.IsVisible = true;
    // }
    //
    // private void Button_OnClick1(object? sender, RoutedEventArgs e)
    // {
    //     OverlayLayer.IsVisible = false;
    // }
    private void Button_OnClick(object? sender, RoutedEventArgs e)
    {
        videoView.MediaPlayer = _mediaPlayer;
        _mediaPlayer.Play(new Media(_libVlc,
            new Uri("https://svipsvip.ffzy-online5.com/20240529/27892_cc72986f/index.m3u8")));
    }
}